package com.qf.android.huihui.view.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.qf.android.huihui.R;
import com.qf.android.huihui.adapter.information.DetailListAdapter;
import com.qf.android.huihui.bean.DetailListBean;
import com.qf.android.huihui.common.InfoRecyclerView;
import com.qf.android.huihui.presenter.DetailListPresenter;
import com.qf.android.huihui.view.activity.DetailListItemActivity;
import com.qf.android.huihui.view.fragment.impl.BaseFragment;
import com.qf.android.huihui.view.fragment.impl.IDetailListView;

public class DetailListFragment extends BaseFragment implements IDetailListView {
    private View view;
    private DetailListAdapter adapter;
    private InfoRecyclerView recyclerView;
    private DetailListPresenter presenter;
    private ImageView empty;
    public DetailListFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_detail_list, container, false);
        presenter = new DetailListPresenter(this, getActivity());
        presenter.getData();
        recyclerView = (InfoRecyclerView) view.findViewById(R.id.detail_recycle);
        empty= (ImageView) view.findViewById(R.id.empty);
        recyclerView.setMode(PullToRefreshBase.Mode.BOTH);
        //创建布局管理对象
        LinearLayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        //设置对应的布局管理器
        recyclerView.getRefreshableView().setLayoutManager(manager);
        return view;
    }

    @Override
    public void setDate(final DetailListBean bean) {
        empty.setVisibility(View.GONE);
        adapter = new DetailListAdapter(getActivity(), bean);
        adapter.onItemClickListener(new DetailListAdapter.DetailListOnClickLister() {
            @Override
            public void onItemClickListener(int position, View view) {
                int content_id = bean.getData().get(position).getContent_id();
                Intent intent=new Intent(getActivity(), DetailListItemActivity.class);
                intent.putExtra("id",content_id);
                startActivity(intent);

            }
        });
        recyclerView.getRefreshableView().setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }


}